package br.igk.isnmp.test;

import java.net.InetAddress;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import br.igk.hibernate.HibernateUtility;
import br.igk.isnmp.bean.oid.dao.OidDao;
import br.igk.isnmp.bean.oid.dao.OidDaoImpl;
import br.igk.isnmp.bean.oid.dao.TipoOidDao;
import br.igk.isnmp.bean.oid.dao.TipoOidDaoImpl;
import br.igk.isnmp.bean.oid.form.Oid;
import br.igk.isnmp.util.SNMPConnection;
import br.igk.isnmp.util.SNMPEntry;

public class SNMPSample3 {

	public static void main(String args[]) {
		PropertyConfigurator.configure("./src/br/igk/config/log/log4j.properties");

		Logger log = Logger.getLogger(SNMPSample3.class);
		log.info("Starting......");

		try {
//			HibernateUtility.openTransaction();
//			HibernateUtility.clean();
//			System.exit(1);

			TipoOidDao tipo = new TipoOidDaoImpl();

			OidDao oidService = new OidDaoImpl();
//			oidService.removeAll();
//			oidService.add(new Oid("1.3.6.1.2.1.1.3.0", "timeticks", "Não sei", tipo.get(1)));
//			oidService.add(new Oid("1.3.6.1.2.1.1.1.0", "uname", "Similar ao comando uname -r", tipo.get(1)));
//			oidService.add(new Oid("1.3.6.1.2.1.1.4.0", "email", "Email", tipo.get(1)));
//			oidService.add(new Oid("1.3.6.1.2.1.1.5.0", "host.name", "Nome do host", tipo.get(1)));

			List<Oid> list = oidService.list();
			SNMPConnection con = new SNMPConnection(0, InetAddress.getByName("192.168.1.1"), "public");

			for (Oid oid: list) {
				SNMPEntry entry = con.getEntry(oid.getOid());
				System.out.println(
					"ID: " + oid.getId() + ", " +
					"OID: " + oid.getOid() + ", " +
					"ALIAS: " + oid.getAlias() + ", " +
					"DESC: " + oid.getDescricao() + ", " +
					"VALUE: " + entry.getSnmpValue().toString()
				);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}


		HibernateUtility.clean();
	}

}